home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / BTKEYCMP.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  71 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)btkeycmp.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10.  
  11. /* library headers */
  12. #include <blkio.h>
  13.  
  14. /* local headers */
  15. #include "btree_.h"
  16.  
  17. /*man---------------------------------------------------------------------------
  18. NAME
  19.      btkeycmp - compare btree keys
  20.  
  21. SYNOPSIS
  22.      #include <btree.h>
  23.  
  24.      int btkeycmp(btp, buf1, buf2)
  25.      btree_t *btp;
  26.      const void *buf1;
  27.      const void *buf2;
  28.  
  29. DESCRIPTION
  30.      The btkeycmp function compares the keys pointed to be buf1 and
  31.      buf2.  buf1 and buf2 must point to keys of the size stored in
  32.      btree btp.  The value returned will be less than, equal to, or
  33.      greater than 0, according as the key pointed to by buf1 is less
  34.      than, equal to, or greater than the key pointed to by buf2.
  35.  
  36.      btkeycmp will fail if one or more of the following is true:
  37.  
  38.      [EINVAL]       btp is not a valid btree pointer.
  39.      [EINVAL]       buf is the NULL pointer.
  40.  
  41. SEE ALSO
  42.      btsearch.
  43.  
  44. ------------------------------------------------------------------------------*/
  45. #ifdef AC_PROTO
  46. int btkeycmp(btree_t *btp, const void *buf1, const void *buf2)
  47. #else
  48. int btkeycmp(btp, buf1, buf2)
  49. btree_t *btp;
  50. const void *buf1;
  51. const void *buf2;
  52. #endif
  53. {
  54.     int    cmp    = 0;        /* result of key comparison */
  55.     int    fld    = 0;        /* field number */
  56.  
  57.     /* compare each field */
  58.     for (fld = 0; fld < btp->fldc; ++fld) {
  59.         cmp = (*btp->fldv[fld].cmp)((char *)buf1 + btp->fldv[fld].offset,
  60.             (char *)buf2 + btp->fldv[fld].offset, btp->fldv[fld].len);
  61.         if (cmp != 0) {
  62.             if (btp->fldv[fld].flags & BT_FDSC) {
  63.                 cmp = -cmp;
  64.             }
  65.             break;
  66.         }
  67.     }
  68.  
  69.     return cmp;
  70. }
  71.